<?php

require_once('lib/utils.php');
require_once('lib/photo.php');

if (isset($_GET['pic']) && isset($_GET['gal'])) {
	?>
	<p>
		<span class="back"><a href="media-photos_list.html">Revenir aux galeries</a>
	</p>
	<?php
	$current = clean_str($_GET['pic']);
	$gal = clean_str($_GET['gal']);
	$pics = photo_list($gal);
	$i = 0;
	$found = false;
	foreach ($pics as $pic) {
		if (basename($pic) == $current) {
			$found = true;
			break;
		}
		++$i;
	}
	
	if ($found) {
		$link = photo_get_link($gal, $current);
		echo '
		<a href="'.$link.'" title="'.$current.'">
			<img src="'.$link.'" alt="'.$current.'" />
		</a>';
		
		?>
		<table style="width: 100%;">
			<tr style="text-align: center;">
		<?php
		// lien image précédente
		if ($i > 0) {
			$link = 'media-photos_view-'.basename($pics[$i - 1]).'-'.$gal.'.html';
			echo '
			<td>
				<a href="'.$link.'">
					<img src="'.$pics[$i - 1].'" alt="previous" />
				</a><br />
				&larr;&nbsp;<a href="'.$link.'">Précédente</a>
			</td>';
		}
		
		// lien image suivante
		if ($i < count($pics) - 1) {
			$link = 'media-photos_view-'.basename($pics[$i + 1]).'-'.$gal.'.html';
			echo '
			<td>
				<a href="'.$link.'">
					<img src="'.$pics[$i + 1].'" alt="next" />
				</a><br />
				<a href="'.$link.'">Suivante</a>&nbsp;&rarr;
			</td>';
		}
		?>
			</tr>
		</table>
	<?php
	}
	else {
		?>
		<p class="error">
			La photo demandée n'existe pas
		</p>
		<?php
	}
}
?>


